package SinglyLinkedList;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;

public class SinglyLinkedListTest {
    SinglyLinkedList list = new SinglyLinkedList();

    @Test  //遍历
    public void test1() {
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);

        list.loop();
    }

    @Test  //遍历
    public void test2() {
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);

        list.loop1(value -> {
            System.out.println(value);
        });
    }

    @Test  //遍历
    public void test3() {
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        list.loop2(value -> {
            System.out.println(value);
        });
    }

    @Test  //遍历
    public void test4() {
        list.addFirst(1);
        list.addFirst(2);
        list.addFirst(3);
        list.addFirst(4);
        for (Integer value : list) {
            System.out.println(value);
        }
    }

    @Test
    public void test5() {
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        Assertions.assertIterableEquals(List.of(1, 2, 3, 4), list);
    }

    @Test
    public void test6() {
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        int i = list.get(5);
        System.out.println(i);
    }

    @Test
    public void test7() {
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.insert(2, 6);
        for (Integer value : list) {
            System.out.println(value);
        }
    }

    @Test
    public void test8() {
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.removeFirst();
        for (Integer value : list) {
            System.out.println(value);
        }
        System.out.println("------------");
        list.removeFirst();
        for (Integer value : list) {
            System.out.println(value);
        }
    }
    @Test
    public void test9(){
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.remove(0);
        for (Integer value : list) {
            System.out.println(value);
        }
    }
    @Test
    public void test10(){
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.loop3(value->{
            System.out.println("before:" + value );
        },value->{
            System.out.println("after:" + value);
        });
    }
}
